// app.js
import request from './utils/axios'
App({
  onLaunch() {
    wx.checkSession({
      success() {
        console.log("成功");
      },
      fail() {
        console.log("失败");
        // 身份失效重新登录
        wx.showModal({
          title: '提示',
          content: 'session信息已过期，重新登录',
          showCancel: false,
          complete: (res) => {
            wx.clearStorageSync()
          }
        })
      }
    })
    // 展示本地存储能力
    const userInfos = wx.getStorageSync("userInfo")
    if (userInfos) {
      let {
        session_key,
        confirm_identity,
        createdAt,
        updatedAt,
        ...userInfo
      } = userInfos
      this.globalData.userInfo = userInfo
    }
    // 挂载封装的请求到this
    this.$axios = request;
    // 获取手机信息
    let systemInfo = wx.getSystemInfoSync()
    this.globalData.systemInfo.windowHeight = systemInfo.windowHeight
    this.globalData.systemInfo.windowWidth = systemInfo.windowWidth
    this.globalData.systemInfo.screenWidth = systemInfo.screenWidth
    this.globalData.systemInfo.screenHeight = systemInfo.screenHeight
    this.globalData.systemInfo.statusBarHeight = systemInfo.statusBarHeight
    // 获取胶囊信息
    /*
    width：菜单按钮的宽度（单位为 px）。
    height：菜单按钮的高度（单位为 px）。
    top：菜单按钮的上边界到屏幕顶部的距离（单位为 px）。
    right：菜单按钮的右边界到屏幕左侧的距离（单位为 px）。
    bottom：菜单按钮的下边界到屏幕顶部的距离（单位为 px）。
    left：菜单按钮的左边界到屏幕左侧的距离（单位为 px）。
    */
    let menuButtonObject = wx.getMenuButtonBoundingClientRect();
    console.log(menuButtonObject);
    // 计算标题宽高 
    this.globalData.systemInfo.CustomBarHeight = menuButtonObject.top + menuButtonObject.bottom - this.globalData.systemInfo.statusBarHeight * 2
    // 计算可视区高度
    this.globalData.visibleArea = this.globalData.systemInfo.windowHeight - this.globalData.systemInfo.CustomBarHeight - this.globalData.systemInfo.statusBarHeight;
    this.globalData.visibleAreaRpx = 750 / this.globalData.systemInfo.windowWidth * this.globalData.visibleArea
    console.log(this.globalData, "这是app中的全局变量");
  },
  globalData: {
    userInfo: {
      nickname: null,
      avatar_url: "https://ruan-cso-1318331856.cos.ap-guangzhou.myqcloud.com/%E5%A4%B4%E5%83%8F.png",
      face_url: null,
      username: null,
      phone: null,
      adress_ID: null,
      address_name: null,
      school_ID: null,
      school_name: null,
      college_ID: null,
      college_name: null,
      sex: 0,
      student_id: null,
      teacher_id: null,
      class_ID: null,
      class_name: null,
      identity_ID: null,
      position_name: null,
      position_ID: null,
      token: null,
      open_id: null
    },
    systemInfo: {
      windowHeight: "",
      windowWidth: "",
      screenWidth: "",
      screenHeight: "",
      statusBarHeight: "",
      CustomBarHeight: "",
    },
    // 可视区
    visibleArea: 0,
    visibleAreaRpx: 0,
    url: 'http://127.0.0.1:3000',
    ws: 'ws://127.0.0.1:8080'
    // url:'http://123.249.111.34:3000',
    // ws:'ws://123.249.111.34:8080'
  }
})